package com.ruima.framework.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class JdbcUtil {
	
private static Properties properties = null;

	public static final String CONTEXT_NAME = "CONTEXT_NAME";	
	public static final String DATA_SOURCE_TYPE = "DATA_SOURCE_TYPE";	
	public static final String DB_DRIVER = "DB_DRIVER";	
	public static final String DB_URL = "DB_URL";	
	public static final String DB_USER = "DB_USER";	
	public static final String DB_PASSWORD = "DB_PASSWORD";	
	public static final String DB_INITIALIZE = "DB_INITIALIZE";	
	public static final String DB_MAXCONNECTION = "DB_MAXCONNECTION";
	public static final String ENV_CONTENT = "ENV_CONTENT";
	public static final String JNDI_DATA_SOURCE = "JNDI_DATA_SOURCE";
	
	
	
	public static void init() {
		if(properties == null){
			properties = new Properties();
			try {
				properties.load(Thread.currentThread().getContextClassLoader()
						.getResourceAsStream("jdbc.properties"));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}		
	}

	public static String getValue(String key) {
		if(properties == null){
			init();
		}
		return properties.getProperty(key);
	}

	public static void updateProperties(String key, String value) {
		if(properties == null){
			init();
		}
		properties.setProperty(key, value);
	}

}
